/*
 * Copyright (c) 2019. Mikes. All rights reserved.
 *
 * You can contact me with sending email to bWlrZXNfMjAxMkAxNjMuY29t for more information!
 */

package com.climber.android.commonsdk.app

import io.ganguo.library.mvp.Config
import io.ganguo.library.mvp.util.AppUtils

/**
 * Created by Mikes at 2019-11-26 21:49
 */
object AppFormStorage {
    /**
     * 仅首次安装显示欢迎页
     *
     * @return
     */
    fun shouldShowWelcomePage(): Boolean {
        return isFirstLaunchAfterDownload()
    }

    /**
     * 是否首次安装
     */
    fun showIfAfterInstalled() : Boolean {
        return Config.getBoolean(AppConstants.CONFIG_LAUNCH_AFTER_INSTALLED, true)
    }

    /**
     * first launching after being downloaded
     */
    fun isFirstLaunchAfterDownload(): Boolean {
        return Config.getBoolean(AppConstants.CONFIG_LAUNCH_AFTER_DOWNLOAD, true)
    }

    /**
     * first launching after being updated
     */
    fun isFirstLaunchAfterUpgrade(changeLocalPreference: Boolean): Boolean {
        val currentV = AppUtils.getAppVersionCode()
        val lastV = Config.getString(AppConstants.LAST_APP_VERSION_CODE, "0")
        if (changeLocalPreference) {
            Config.putString(AppConstants.LAST_APP_VERSION_CODE, "" + currentV)
        }
        return try {
            currentV > Integer.parseInt(lastV)
        } catch (e: NumberFormatException) {
            false
        }
    }


}